package com.tree.mybatisdemo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tree.mybatisdemo.manager.SyncDemoManager;
import com.tree.mybatisdemo.mapper.TbUserMapper;
import com.tree.mybatisdemo.pojo.TbUser;
import com.tree.mybatisdemo.service.UserService;

/**
 * @ClassName UserServiceImpl
 * @Description: TODO
 * @Author: myl
 * @Create_time:2021/4/19 14:41
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private TbUserMapper userMapper;

    @Autowired
    private SyncDemoManager syncDemoManager;

    @Override
    public List<TbUser> getUserPageList() {
        PageHelper.startPage(1, 5);

        List<TbUser> tbUsers = userMapper.selectPageList();
        tbUsers.forEach(tbUser -> System.out.println(tbUser.getUserId() + "-" + tbUser.getUserName()));

        PageInfo<TbUser> tbUserPageInfo = new PageInfo<>(tbUsers);
        System.out.println("total:" + tbUserPageInfo.getTotal());

        return tbUserPageInfo.getList();
    }

    @Override
    public void demoService() {
        System.out.println("开始调用service");
        syncDemoManager.print();

        System.out.println("调用service结束");
    }
}
